package zhuyun.code

fun main(args:Array<String>){
    var s = 0f
    val BigBag: Bags
    val mediumBag: Bags
    val smallRedBag: Bags
    val smallWhiteBag: Bags
    var sp: Goods
    BigBag = Bags("大袋子")
    mediumBag = Bags("中袋子")
    smallRedBag = Bags("红色小袋子")
    smallWhiteBag = Bags("白色小袋子")
    sp = Goods("婺源特产", 2, 7.9f)
    smallRedBag.add(sp)
    sp = Goods("婺源地图", 1, 9.9f)
    smallRedBag.add(sp)
    sp = Goods("韶关香菇", 2, 68f)
    smallWhiteBag.add(sp)
    sp = Goods("韶关红茶", 3, 180f)
    smallWhiteBag.add(sp)
    sp = Goods("景德镇瓷器", 1, 380f)
    mediumBag.add(sp)
    mediumBag.add(smallRedBag)
    sp = Goods("李宁牌运动鞋", 1, 198f)
    BigBag.add(sp)
    BigBag.add(smallWhiteBag)
    BigBag.add(mediumBag)
    println("您选购的商品有：")
    BigBag.show()
    s = BigBag.calculation()
    println("要支付的总价是：" + s + "元")

}
interface Articles{
    fun calculation():Float
    fun show()
}
class Goods(private val name:String, private val quantity :Int, private val unitPrice:Float):Articles{
    override fun calculation(): Float {
        return unitPrice * quantity
    }

    override fun show() {
        println("$name,价格:$unitPrice,数量:$quantity")
    }

}
class Bags(val name:String):Articles{
    private val bags = mutableListOf<Articles>()
    fun add(c:Articles){
        bags.add(c)
    }
    fun remove(c:Articles){
        bags.remove(c)
    }
    fun getChild(i:Int):Articles{
        return bags[i]
    }

    override fun calculation(): Float {
        var total = 0.0f
        for(c in bags){
            total +=c.calculation()
        }
        return total
    }

    override fun show() {
        for(c in bags){
            c.show()
        }
    }


}